package com.zzl.springboot_mybatis_demo.controller.seckill;

import com.zzl.springboot_mybatis_demo.service.seckill.SeckillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * description: 秒杀Controller
 * @author 朱正磊
 * @date 2019-12-04 10:40:41
 */
@Slf4j
@RestController
@RequestMapping("/api/seckill")
public class SeckillController {

    @Resource(name = "seckillServiceImpl")
    private SeckillService seckillService;

    /**
     * description：查询秒杀活动特价商品的信息
     * user 朱正磊
     * time 2019-05-12 13:33
     * @param productId 商品ID
     * @return 返回秒杀活动特价商品的信息
     */
    @RequestMapping("/query/{productId}")
    public String query(@PathVariable("productId") String productId) {
        return seckillService.querySeckillProductInfo(productId);
    }

    /**
     * description：秒杀，抢到了会返回商品剩余的库存量，没有抢到的话会返回提示信息"哎呦喂，人也太多了吧，请换个姿势再试试~~~"
     * user 朱正磊
     * time 2019-05-12 13:37
     * @param productId 商品ID
     * @return 返回秒杀活动特价商品的信息
     */
    @RequestMapping("/order/{productId}")
    public String secKill(@PathVariable("productId") String productId) {
        log.info("@seckill request, productId: " + productId);
        seckillService.orderProductMockDiffUser(productId);
        return seckillService.querySeckillProductInfo(productId);
    }

}
